﻿#region Using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Text;
using System.ComponentModel; 
#endregion

namespace AifMessageHeaderEditor.Lib.Data.MessageDocument.Message.Header
{
    public class MessageHeaderData : MessageDataBase
    {
        #region members and consts

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region constructor

        public MessageHeaderData(XmlNode headerNode)
            : base(headerNode)
        {}

        #endregion

        #region Header

        /// <summary>
        /// The SourceEndpointUser of the Aif-message
        /// </summary>
        public string SourceEndpointUser
        {
            get
            {
                return _xmlNode[AppCommon.AIF_HEADER_SOURCEPOINTENDUSER].InnerText;
            }
            set
            {

                if (value != this.SourceEndpointUser)
                {
                    _xmlNode[AppCommon.AIF_HEADER_SOURCEPOINTENDUSER].InnerText = value;
                    NotifyPropertyChanged(AppCommon.AIF_HEADER_SOURCEPOINTENDUSER);
                }
            }
        }

        /// <summary>
        /// The MessageId of the Aif-message.
        /// </summary>
        public string MessageId
        {
            get
            {
                return _xmlNode[AppCommon.AIF_HEADER_MESSAGEID].InnerText;
            }
            set
            {
                if (value != this.MessageId)
                {
                    _xmlNode[AppCommon.AIF_HEADER_MESSAGEID].InnerText = value;
                    NotifyPropertyChanged(AppCommon.AIF_HEADER_MESSAGEID);
                }
            }
        }

        /// <summary>
        /// The Action of the Aif-message
        /// </summary>
        public string Action
        {
            get
            {
                return _xmlNode[AppCommon.AIF_HEADER_ACTION].InnerText;
            }
            set
            {
                if (value != this.Action)
                {
                    _xmlNode[AppCommon.AIF_HEADER_ACTION].InnerText = value;
                    NotifyPropertyChanged(AppCommon.AIF_HEADER_ACTION);
                }
            }
        }

        /// <summary>
        /// The DestinationEndpoint of the Aif-message
        /// </summary>
        public string DestinationEndpoint
        {
            get
            {
                return _xmlNode[AppCommon.AIF_HEADER_DESTINATIONENDPOINT].InnerText;
            }
            set
            {
                if (value != this.DestinationEndpoint)
                {
                    _xmlNode[AppCommon.AIF_HEADER_DESTINATIONENDPOINT].InnerText = value;
                    NotifyPropertyChanged(AppCommon.AIF_HEADER_DESTINATIONENDPOINT);
                }
            }
        }

        /// <summary>
        /// The ConversationId of the Aif-message
        /// </summary>
        public string ConversationId
        {
            get
            {
                return _xmlNode[AppCommon.AIF_HEADER_CONVERSATIONID].InnerText;
            }
            set
            {
                if (value != this.SourceEndpoint)
                {
                    _xmlNode[AppCommon.AIF_HEADER_CONVERSATIONID].InnerText = value;
                    NotifyPropertyChanged(AppCommon.AIF_HEADER_CONVERSATIONID);
                }
            }
        }

        /// <summary>
        /// The RequestMessageId of the Aif-message
        /// </summary>
        public string RequestMessageId
        {
            get
            {
                return _xmlNode[AppCommon.AIF_HEADER_REQUESTMESSAGEID].InnerText;
            }
            set
            {
                if (value != this.SourceEndpoint)
                {
                    _xmlNode[AppCommon.AIF_HEADER_REQUESTMESSAGEID].InnerText = value;
                    NotifyPropertyChanged(AppCommon.AIF_HEADER_REQUESTMESSAGEID);
                }
            }
        }

        /// <summary>
        /// The SourceEndpoint of the Aif-message
        /// </summary>
        public string SourceEndpoint
        {
            get
            {
                return _xmlNode[AppCommon.AIF_HEADER_SOURCEENDPOINT].InnerText;
            }
            set
            {
                if (value != this.SourceEndpoint)
                {
                    _xmlNode[AppCommon.AIF_HEADER_SOURCEENDPOINT].InnerText = value;
                    NotifyPropertyChanged(AppCommon.AIF_HEADER_SOURCEENDPOINT);
                }
            }
        }

        #endregion

        #region methods : Notification

        public override void NotifyChanges()
        {
            NotifyPropertyChanged(AppCommon.AIF_HEADER_ACTION);
            NotifyPropertyChanged(AppCommon.AIF_HEADER_CONVERSATIONID);
            NotifyPropertyChanged(AppCommon.AIF_HEADER_DESTINATIONENDPOINT);
            NotifyPropertyChanged(AppCommon.AIF_HEADER_MESSAGEID);
            NotifyPropertyChanged(AppCommon.AIF_HEADER_REQUESTMESSAGEID);
            NotifyPropertyChanged(AppCommon.AIF_HEADER_SOURCEENDPOINT);
            NotifyPropertyChanged(AppCommon.AIF_HEADER_SOURCEPOINTENDUSER);
        }
        /// <summary>
        /// used for the databinding: notifies the controles that are binded 
        /// to the object or properties.
        /// </summary>
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion
    }
}
